package com.jingsai.Service;

import com.jingsai.Mapper.*;
import com.jingsai.POJO.Common.*;
import lombok.RequiredArgsConstructor;

import java.util.*;

@RequiredArgsConstructor
@org.springframework.stereotype.Service
public class Service {
    final TodayProblemIDMapper todayProblemIDMapper;
    final ScoreHistoryMapper scoreHistoryMapper;
    final SubmitLastMapper submitLastMapper;
    final UserScoreMapper userScoreMapper;
    final SubmitHistoryMapper submitHistoryMapper;

    public void insertProblem(TodayProblemId problem) {
        todayProblemIDMapper.insert(problem);
    }

    public void insertSubmitHistory(SubmitHistory submitHistory) {
        submitHistoryMapper.insert(submitHistory);
    }

    public void insertSubmitLast(SubmitLast submitLast) {
        submitLastMapper.insert(submitLast);
    }

    public void insertScoreHistory(ScoreHistory scoreHistory) {
        scoreHistoryMapper.insert(scoreHistory);
    }

    public void insertUserScore(UserScore userScore){userScoreMapper.insert(userScore);}

    public ArrayList<SubmitLast> selectSubmitLast() {
        return submitLastMapper.selectAll();
    }

    public void updateSubmitLast(int id) {
        submitLastMapper.update(id);
    }

    public void updateScoreHistory(ScoreHistory hs) {
        scoreHistoryMapper.update(hs);
    }
    public void updateUserScore(UserScore us){
        userScoreMapper.update(us);
    }

    public ArrayList<TodayProblemId> selectProblemId() {
        return todayProblemIDMapper.selectAll();
    }

    public List<SubmitHistory> selectSubmitHistoryBy_submit_item(String id) {
        Map<String, Object> columnMap = new HashMap<>();
        columnMap.put("submit_item", id);
        return submitHistoryMapper.selectByMap(columnMap);
    }

    public List<TodayProblemId> selectProblemIdBy_problem_date(String date) {
        Map<String, Object> columnMap = new HashMap<>();
        columnMap.put("problem_date", date);
        return todayProblemIDMapper.selectByMap(columnMap);
    }

    public List<ScoreHistory> selectScoreHistoryBy_user_infoAndDate(String Userinfo, Date date) {
        Map<String, Object> columnMap = new HashMap<>();
        columnMap.put("user_info", Userinfo);
        columnMap.put("submit_time",date);
        return scoreHistoryMapper.selectByMap(columnMap);
    }
    public List<ScoreHistory> selectScoreHistoryBy_user_info(String Userinfo) {
        Map<String, Object> columnMap = new HashMap<>();
        columnMap.put("user_info", Userinfo);
        return scoreHistoryMapper.selectByMap(columnMap);
    }




    public List<UserScore> selectUserScoreBy_user_info(String Userinfo){
        Map<String, Object> columnMap = new HashMap<>();
        columnMap.put("user_info", Userinfo);
        return userScoreMapper.selectByMap(columnMap);
    }

    public ArrayList<UserScore> selectUserScore() {
        return userScoreMapper.selectUserScore();
    }
}
